/**
 * 
 */
package org.youisoft.summer.evaluator.eval;

import org.youisoft.summer.evaluator.EvalConst;

/**
 * 
 * @author zijiang.jl
 * 
 * 转化表达式中的部分字符
 *
 */
public interface ExpressionTransformer extends org.youisoft.lifecircle.Destroyable{
	
	/**
	 * 
	 * @param expression
	 * @return
	 */
	public String transform(String expression);
	
	
	/**
	 * 
	 * @author zijiang.jl
	 * 默认的表达式转化
	 *
	 */
	class DefaultExpressionTransformer implements ExpressionTransformer{
		
		private java.util.Map<String, String> strMap=new java.util.HashMap<String, String>();
		
		@Override
		public String transform(String expression) {
			if(expression==null) return null;
			if(strMap.get(expression)==null){
				java.lang.StringBuilder sb=new java.lang.StringBuilder(EvalConst.leftParenthesisPlaceHolder);
				sb.append(expression.replace(" ", "").trim());
				sb.append(EvalConst.rightParenthesisPlaceHolder);
				String value=sb.toString();
				strMap.put(expression, value);
				return value;
			}else{
				return strMap.get(expression);
			}

		}

		@Override
		public void destory() {
			strMap=null;
			
		}

		@Override
		public void clear() {
			strMap.clear();
			
		}
		
		
		
		
	}
}
